#!/bin/bash

# 安全配置管理系统启动脚本（未测试）

# 显示颜色
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# 显示欢迎信息
echo -e "${GREEN}启动安全配置管理系统...${NC}"

# 检查Python环境
if command -v python3 &>/dev/null; then
    PYTHON_CMD="python3"
elif command -v python &>/dev/null; then
    PYTHON_CMD="python"
else
    echo -e "${RED}未找到Python，请确保已安装Python 3.7或更高版本${NC}"
    echo -e "${YELLOW}请访问 https://www.python.org/downloads/ 下载安装${NC}"
    exit 1
fi

PYTHON_VERSION=$($PYTHON_CMD --version)
echo -e "${GREEN}已检测到Python: $PYTHON_VERSION${NC}"

# 检查主密钥环境变量
if [ -z "$SECURECONFIGMASTERKEY" ]; then
    echo -e "${YELLOW}警告: 未检测到SECURECONFIGMASTERKEY环境变量${NC}"
    echo -e "${YELLOW}首次运行系统时将生成新密钥，请按照提示操作${NC}"
else
    echo -e "${GREEN}已检测到主密钥环境变量${NC}"
fi

# 检查Streamlit是否已安装
if command -v streamlit &>/dev/null; then
    STREAMLIT_VERSION=$(streamlit --version)
    echo -e "${GREEN}已检测到Streamlit: $STREAMLIT_VERSION${NC}"
else
    echo -e "${YELLOW}未找到Streamlit，尝试安装...${NC}"
    $PYTHON_CMD -m pip install streamlit
fi

# 检查项目依赖
if [ -f "requirements.txt" ]; then
    echo -e "${GREEN}正在检查项目依赖...${NC}"
    $PYTHON_CMD -m pip install -r requirements.txt
else
    echo -e "${YELLOW}警告: 未找到requirements.txt文件${NC}"
fi

# 确保脚本目录存在
mkdir -p configs

# 设置Python路径
export PYTHONPATH=$(pwd)

# 启动应用
echo -e "${GREEN}正在启动应用...${NC}"
streamlit run secure_config_manager/webui/app.py 